package com.alibaba.citrus.cr.common.enums.ordercenter;

import org.apache.commons.lang.StringUtils;

import java.util.Arrays;
import java.util.Objects;

public enum SalesOrderBusinessTypeEnum {
    NORMAL_TEMPERATURE("常温", 11),
    FRESH_MILK("鲜奶", 1201),
    LOW_TEMPERATURE("低温", 1202),
    FROZEN("冰品", 13),
    CHEESE("奶酪", 14),
    INDUSTRY_CHEESE("工业奶酪", 16),
    MILK_POWDER("奶粉", 15),
    SPORTS_NUTRITION("运动营养", 19),
    PLANT_PROTEIN("植物蛋白", 17),
    PERSONALIZED_NUTRITION("精准营养", 18),
    NOT_MENGNIU_PRODUCT("非蒙牛产品", 98),

    ;

    /**
     * 业态类型名称
     */
    private String desc;
    /**
     * 业态类型编码
     */
    private Integer code;

    SalesOrderBusinessTypeEnum(String desc, Integer code) {
        this.desc = desc;
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public static SalesOrderBusinessTypeEnum of(Integer code) {
        return Arrays.stream(SalesOrderBusinessTypeEnum.values()).filter(source -> Objects.equals(code, source.getCode())).findFirst().orElse(null);
    }

    public static SalesOrderBusinessTypeEnum of(String code) {
        return Arrays.stream(SalesOrderBusinessTypeEnum.values()).filter(source -> StringUtils.equals(code, source.getCode().toString())).findFirst().orElse(null);
    }

    public static String descByCode(Integer code) {
        SalesOrderBusinessTypeEnum typeEnum = of(code);
        return Objects.nonNull(typeEnum) ? typeEnum.getDesc() : null;
    }

}
